package com.flame.system.log.controller;

import java.util.List;

import com.flame.auth.core.annotation.HasAuth;
import com.flame.core.protocol.PageResult;
import com.flame.core.protocol.Result;
import com.flame.system.log.controller.vo.UserLoginLogVo;
import com.flame.system.log.service.UserLoginLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * flame_user_login_log 登录日志表
 *
 * @author 吴欣童
 * @since 2023-02-23 18:22:33
 */
@RestController
public class UserLoginLogController {

    @Autowired
    private UserLoginLogService userLoginLogService;

    @HasAuth("login-log")
    @PostMapping("/system/log/login/page")
    public PageResult pageUserLoginLog(@RequestBody UserLoginLogVo userLoginLogVo) {
        return PageResult.success(userLoginLogService.pageUserLoginLog(userLoginLogVo));
    }

    @HasAuth("login-log:batch-delete")
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/system/log/login/batch-delete")
    public Result batchDeleteUserLoginLog(@RequestBody List<Long> logIdList) {
        userLoginLogService.batchDelete(logIdList);
        return Result.success();
    }

    @HasAuth("login-log:clear")
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/system/log/login/clear")
    public Result clearLog() {
        userLoginLogService.clear();
        return Result.success();
    }
}
